package com.gopay.cashier.service.gsrt.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gopay.cashier.service.gsrt.GsrtService;
import com.gopay.common.constants.trans.TxnStaCode;
import com.gopay.common.cps.dao.gsrt.GsrtAccountRechargeDao;
import com.gopay.common.cps.dao.order.CpsGeneralMainOrderQueryDAO;
import com.gopay.common.cps.manager.gsrt.GsrtAccountRechargeQueryManager;
import com.gopay.common.domain.cps.CpsGenMainOrder;
import com.gopay.common.domain.gsrt.GsrtAccountRecharge;
import com.gopay.common.exception.GopayException;
@Service("gsrtService")
public class GsrtServiceImpl implements GsrtService {
	
	protected final static Logger logger = LoggerFactory.getLogger(GsrtServiceImpl.class);
	
	@Resource(name = "gsrtAccountRechargeDao")
	private GsrtAccountRechargeDao gsrtAccountRechargeDao;
    
    @Resource(name = "gsrtAccountRechargeQueryManager")
	private GsrtAccountRechargeQueryManager gsrtAccountRechargeQueryManager;
    
    @Resource(name="cpsGeneralMainOrderQueryDAO")
    protected CpsGeneralMainOrderQueryDAO cpsGeneralMainOrderQueryDAO;


	@Override
	public void updateGsrtRecharge(String gopayOrderId) throws GopayException {
		CpsGenMainOrder main = cpsGeneralMainOrderQueryDAO.findByGopayOrderId(gopayOrderId);
		List<GsrtAccountRecharge> gsrtAccountRechargeList = 
				gsrtAccountRechargeQueryManager.getByGopayOrderId(main.getGopayOrderId());
		if(gsrtAccountRechargeList.size() > 0 && main != null){
			GsrtAccountRecharge recharge = gsrtAccountRechargeList.get(0);
    		recharge.setCurType(main.getCurType());
    		recharge.setLastUpdTs(new Date());

    		recharge.setOrderDealAmt(main.getOrderDealAmt());
    		recharge.setOrderFeePayer(main.getOrderFeePayer());
    		recharge.setOrderRealFeeAmt(main.getOrderRealFeeAmt());
    		recharge.setTotalOrderAmt(main.getTotalOrderAmt());
    		recharge.setTotalOrderFeeAmt(main.getTotalOrderFeeAmt());
    		
    		recharge.setOrderStlmTime(main.getOrderStlmTime());
    		recharge.setOutPayAcct(main.getOutPayAcct());
    		recharge.setOutStlmId(main.getOutStlmId());
    		
    		recharge.setReversalFlag(main.getReversalFlag());
    		recharge.setMerCommPayer(main.getMerCommPayer());
    		recharge.setMerCommAmt(main.getMerCommAmt());
    		
    		recharge.setPayCustId(main.getPayCustId());
    		recharge.setPayAcct(main.getPayAcct());
    		recharge.setOrderType(main.getOrderType());
    		recharge.setPayChannel(main.getPayChannel());
    		recharge.setTxnStaCd(main.getTxnStaCd());

			gsrtAccountRechargeDao.update(recharge);
    	}
	}

}
